﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Globalization;
using Public;

namespace WebsiteAdmin.Wilson.ProInfo.Handler
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class SerList : IHttpHandler
    {
        int catId = 0;
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Cookie.AdminLoginName != null && Cookie.AdminLoginName != "") 
            {
                catId = Convert.ToInt16(context.Request["CatId"], CultureInfo.InvariantCulture);
                context.Response.Write(SerListByCatId(Global.ConnWilson, catId));
            }
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private string SerListByCatId(string strCon,int catId) 
        {
            string rtnStr = string.Empty;
            using (DataTable dt = Bll.Series.MULTIPLE(strCon, catId))
            {
                if (dt != null && dt.Rows.Count > 0)
                {
                    rtnStr = "{\"Total\":\"" + dt.Rows.Count + "\",\"List\":[";
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        rtnStr += "{"+
                                    "\"PKID\":\"" + dt.Rows[i]["PKID"] + "\",\"SeriesName\":\"" + dt.Rows[i]["SeriesName"] + "\""
                                    +"},";
                    }
                    rtnStr = rtnStr.Substring(0, rtnStr.Length - 1);
                }
                rtnStr += "]}";
            }
            return rtnStr;
        }
    }
}
